
import java.io.*;
import java.net.*;

public class TCPListener implements Runnable {

	private int port;
	private boolean finished = false;
	
	public TCPListener(int port){
		this.port = port;

	}
	
	@Override
	public void run() {
		
		//on connect
		try {

			ServerSocket ss = new ServerSocket(port);
			Socket cSocket = ss.accept();
			String input = "foo";
			
			//grab the sockets inputstream	
			BufferedReader in = new BufferedReader(new InputStreamReader(cSocket.getInputStream()));
			
			//loop forever
			while((input = in.readLine()) != null){
					System.out.println(input);				
			}
			
			ss.close();
			cSocket.close();
			return;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
